﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Globalization;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.APP.Classes;
using _WebShared.Classes;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_EmployeeWorkHistories : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private IEmployeeBLL empBLL = new EmployeeBLL();
        Main main = new Main();

        //private EmployeeInfo empInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadHeader();
        }

        public void LoadHeader()
        {
            string strEmpSeq = ssMng.EmpSeq;
            //DateTime dtRetireYear;

            if (strEmpSeq.Length == 0)
                return;

            //empInfo = emp.GetEmployeeInfo(Int32.Parse(strEmpSeq));

            //lblDateAdmitted.Text = string.Format("{0:dd/MM/yyyy}", empInfo.AdmittedDate);
            //lblDateWorkStarted.Text = string.Format("{0:dd/MM/yyyy}", empInfo.WorkStartDate);
            //lblDateProbationEnd.Text = string.Format("{0:dd/MM/yyyy}", empInfo.ProbationEndDate);
            //lblDateLatestPos.Text = string.Format("{0:dd/MM/yyyy}", empInfo.LatestPositionDate);
            //lblDateLatestWorkingJobsite.Text = string.Format("{0:dd/MM/yyyy}", empInfo.LatestWorkingJobSiteDate);
            //lblDateLatestClass.Text = string.Format("{0:dd/MM/yyyy}", empInfo.LatestClassDate);
            //lblQuit.Text = string.Format("{0:dd/MM/yyyy}", empInfo.QuitDate);

            //if (empInfo.BirthDate.HasValue)
            //{
            //    dtRetireYear = Convert.ToDateTime(DateTimeX.ForceToDate(empInfo.BirthDate.ToString(), true));

            //    if (dtRetireYear.Month < 10 || (dtRetireYear.Month == 10 && dtRetireYear.Day < 2))
            //        lblRetireYear.Text = dtRetireYear.AddYears(603).Year.ToString();
            //    else
            //        lblRetireYear.Text = dtRetireYear.AddYears(613).Year.ToString();
            //}
            //else
            //    lblRetireYear.Text = "-";

            //if (empInfo.AdmittedDate.HasValue)
            //{
            //    DateTime dt = (DateTime)DateTimeX.ForceToDate(empInfo.AdmittedDate.ToString(), true);
            //    lblYear.Text = main.CalculateAge(dt).ToString();
            //    lblMonth.Text = main.CalculateAgeMonth(dt).ToString();
            //    lblDay.Text = main.CalculateAgeDay(dt).ToString();
            //}
            //else
            //{
            //    lblYear.Text = "-";
            //    lblMonth.Text = "-";
            //    lblDay.Text = "-";
            //}
        }

        protected void RadPanelBar1_ItemClick(object sender, RadPanelBarEventArgs e)
        {
            string strEmpSeq = ssMng.EmpSeq;
            RadGrid grd1 = null;

            if (e.Item.Expanded)
            {
                switch (e.Item.Index)
                {
                    case 0:
                        grd1 = (RadGrid)RadPanelBar1.Items[0].Items[0].FindControl("RadGridParentHistory");
                        //grd1.DataSource = parent.SelectEmployeeParents(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 1:
                        grd1 = (RadGrid)RadPanelBar1.Items[1].Items[0].FindControl("RadGridSpouseHistory");
                        //grd1.DataSource = spouse.SelectEmployeeSpouses(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 2:
                        grd1 = (RadGrid)RadPanelBar1.Items[2].Items[0].FindControl("RadGridChildrenHistory");
                        //grd1.DataSource = child.LoadGridEmployeeChildrens(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 3:
                        grd1 = (RadGrid)RadPanelBar1.Items[3].Items[0].FindControl("RadGridContactHistory");
                        //grd1.DataSource = cont.SelectEmployeeContacts(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 4:
                        grd1 = (RadGrid)RadPanelBar1.Items[4].Items[0].FindControl("RadGridNameHistory");
                        //grd1.DataSource = name.SelectEmployeeNameHistories(strEmpSeq);
                        grd1.DataBind();
                        break;
                }
            }
        }

        protected void RadGrid_ItemCommand(object source, GridCommandEventArgs e)
        {
            RadGrid grd1 = (RadGrid)source;
            string strEmpSeq = ssMng.EmpSeq;

            switch (grd1.ID)
            {
                case "RadGridParentHistory":
                    //grd1.DataSource = parent.SelectEmployeeParents(strEmpSeq);
                    break;
                case "RadGridSpouseHistory":
                    //grd1.DataSource = spouse.SelectEmployeeSpouses(strEmpSeq);
                    break;
                case "RadGridChildrenHistory":
                    //grd1.DataSource = child.LoadGridEmployeeChildrens(strEmpSeq);
                    break;
                case "RadGridContactHistory":
                    //grd1.DataSource = cont.SelectEmployeeContacts(strEmpSeq);
                    break;
                case "RadGridNameHistory":
                    //grd1.DataSource = name.SelectEmployeeNameHistories(strEmpSeq);
                    break;
            }

            if (e.CommandName != RadGrid.ExpandCollapseCommandName)
            {
                grd1.DataBind();
            }
        }

        public string GetTrueFalseImage(string strCompare, string strTrue, string strFalse
            , string strTrueImageUrl, string strFalseImageUrl)
        {
            if (strCompare == strTrue)
                return strTrueImageUrl;
            else if (strCompare == strFalse)
                return strFalseImageUrl;
            else
                return null;
        }
    }
}